package com.bwie.home.backstage.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.home.backstage.entity.HousesUserReplyEntity;
import com.bwie.home.backstage.service.impl.HousesUserReplyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.home.backstage.entity.UserHousesRemarkEntity;
import com.bwie.home.backstage.service.UserHousesRemarkService;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.R;



/**
 * 
 *
 * @author sy
 * @email sunlightcs@gmail.com
 * @date 2021-09-10 09:46:41
 */
@RestController
@RequestMapping("backstage/userhousesremark")
public class UserHousesRemarkController {
    @Autowired
    private UserHousesRemarkService userHousesRemarkService;

    @Autowired
    private HousesUserReplyServiceImpl housesUserReplyService;


    //查看用户点评
    @RequestMapping("/UserHousesRemarkList")
    public R UserHousesRemarkList(@RequestBody Map<String, Object> params){
        PageUtils page = userHousesRemarkService.UserHousesRemarkList(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userHousesRemarkService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{remarkId}")
    public R info(@PathVariable("remarkId") Integer remarkId){
		UserHousesRemarkEntity userHousesRemark = userHousesRemarkService.getById(remarkId);

        return R.ok().put("userHousesRemark", userHousesRemark);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserHousesRemarkEntity userHousesRemark){
		userHousesRemarkService.save(userHousesRemark);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserHousesRemarkEntity userHousesRemark){
		userHousesRemarkService.updateById(userHousesRemark);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] remarkIds){
		userHousesRemarkService.removeByIds(Arrays.asList(remarkIds));

        return R.ok();
    }
    //单删
    @RequestMapping("/delete/{remarkId}")
    public R delete(@PathVariable("remarkId") Integer remarkId){
        UserHousesRemarkEntity remark = userHousesRemarkService.getremarkId(remarkId);


        boolean remove = housesUserReplyService.remove(new QueryWrapper<HousesUserReplyEntity>().
                eq("user_id", remark.getUserId()).
                eq("houses_id", remark.getHousesId()));
        boolean b = userHousesRemarkService.removeById(remarkId);

        if(b){
            return R.ok();
        }
        return R.error();
    }

}
